﻿[
    {
        $project: {
            "wpp": "$$ROOT",
            "_id": 0
        }
    },
    {
        $lookup: {
            localField: "wpp.people",
            from: "peoples",
            foreignField: "_id",
            as: "p"
        }
    },
    {
        $unwind: {
            path: "$p",
            preserveNullAndEmptyArrays: true
        }
    },
    {
        $lookup: {
            localField: "wpp._id",
            from: "tmworkplanpeopleitems",
            foreignField: "wpp",
            as: "wppi"
        }
    },
    {
        $unwind: {
            path: "$wppi",
            preserveNullAndEmptyArrays: true
        }
    },
    {
        $lookup: {
            localField: "wppi.work_time",
            from: "tmworktimes",
            foreignField: "_id",
            as: "wt"
        }
    },
    {
        $unwind: {
            path: "$wt",
            preserveNullAndEmptyArrays: true
        }
    },
    {
        $lookup: {
            localField: "p.ou",
            from: "organizationunits",
            foreignField: "_id",
            as: "ou"
        }
    },
    {
        $unwind: {
            path: "$ou",
            preserveNullAndEmptyArrays: true
        }
    },
    {
        $match: {
            "wpp.date": {
                $gte: new ISODate('@CalcStartTime'),
                $lte: new ISODate('@CalcEndTime')
            }
        }
    },
    {
        $project: {
            "_id": "$wpp._id",
            "people_no": "$p.people_no",
            "people_name": "$p.people_name",
            "ledger_account": "$p.custom_fields_for_query.650a58aa4853fe0357c84140", // 会计科目
            "people_category": "$p.custom_fields_for_query.650a58aa4853fe0357c84142", // 人员类别
            "is_researcher": "$p.custom_fields_for_query.650a58aa4853fe0357c84143", // 是否研发人员
            "date": "$wpp.date",
            "is_job_day": "$wpp.is_job_day",
            "is_holiday_day": "$wpp.is_holiday_day",
            //"is_ax_day": "$wpp.is_ax_day",
            //"is_exchange_off_day": "$wpp.is_exchange_off_day",
            "is_cross_day": "$wt.is_cross_day",
            "name": "$wt.name",
            "start": "$wt.start",
            "end": "$wt.end",
            "work_mins": "$wt.work_mins",
            "break_mins": "$wt.break_mins",
            "break_start": "$wt.break_start",
            "break_end": "$wt.break_end",
            "break_start2": "$wt.break_start2",
            "break_end2": "$wt.break_end2",
            "ou_code": "$ou.ou_code",
            "ou_name": "$ou.ou_name"
        }
    }
]